package king.dominic.jlibrary.activity;

import android.app.Activity;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;

import java.util.ArrayList;

import king.dominic.jlibrary.util.PermissionUtil;

/**
 * Created by king on 2017/4/12.
 * OriginPermissionActivity
 */

public class OriginPermissionActivity extends AppCompatActivity implements PermissionUtil.PermissionHandler {
    private ArrayList<PermissionUtil.PermissionItem> permissionArray;

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        PermissionUtil.permissionRequest(requestCode, permissions, grantResults, permissionArray);
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }

    @Override
    public void add(PermissionUtil.PermissionItem item) {
        if (permissionArray == null) permissionArray = new ArrayList<>();
        permissionArray.add(item);
    }

    @Override
    public Activity getActivity() {
        return this;
    }

    @Override
    public void handlerRequestPermissions(@NonNull String[] permissions, int requestCode) {
        ActivityCompat.requestPermissions(this,permissions,requestCode);
    }
}
